package com.sinothk.server.plus.qrcode;

import com.google.zxing.Result;

import java.io.File;

public class QrCodeManager {

    /**
     * 生成条形码
     *
     * @param value
     * @param resultFile
     */
    public void createOneCode(String value, File resultFile) {
        GenerateCodeCreator.generateCode(resultFile, value);
    }

    /**
     * 图片识别条形码
     *
     * @param codeFile
     * @return
     * @throws Exception
     */
    public String readOneCode(File codeFile) throws Exception {
        return GenerateCodeCreator.readCode(codeFile);
    }

    /**
     * 生成二维码
     *
     * @param value
     * @param resultFile
     */
    public void createTwoCode(String value, File resultFile) {
        QrCodeCreator.generateQRCode(resultFile, value);
    }

    /**
     * 识别二维码
     *
     * @param file
     * @return
     * @throws Exception
     */
    public String readTwoCode(File file) throws Exception {
        Result result = QrCodeCreator.readQRCode(file);
        return new String(result.getText().getBytes("GBK"), "GBK");
    }
}
